package com.ktjy.sample.note12and17;

import java.lang.reflect.Field;

public class FruitfoUtll {
    public static void getFruieInfo(Class <?> clazz){
        String strFruitName=" 水果名称 ";
        String strFruitColor=" 水果颜色 ";
        String strFruitProvider="供应商信息 ";

        Field [] fields = clazz.getDeclaredFields();//获取所有属性
        for(Field field:fields){
            if (field.isAnnotationPresent(FruitName.class)){
                FruitName fruitName = field.getAnnotation(FruitName.class);
                strFruitName = strFruitName+fruitName.value();
                System.out.println(strFruitName);
            } else if (field.isAnnotationPresent(FruirtColor.class)) {
                FruirtColor fruitColor = field.getAnnotation(FruirtColor.class);
                strFruitColor = strFruitColor+fruitColor.fruitColor().toString();
                System.out.println(strFruitColor);
            } else if (field.isAnnotationPresent(FruitProider.class)) {
                FruitProider fruitProider = field.getAnnotation(FruitProider.class);
                strFruitProvider =strFruitProvider+" 供应商编号："+fruitProider.id()+" 供应商名称："+fruitProider.name()+" 供应商地址："+fruitProider.address();
                System.out.println(strFruitProvider);
            }
        }
    }
}
